package com.spring.oaassist.web.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.spring.oaassist.web.dao.TaskMapper;
import com.spring.oaassist.web.model.Task;
import com.spring.oaassist.web.service.TaskService;
import com.spring.security.core.util.UpdateMap;
import com.spring.security.web.dao.CommonMapper;
import com.spring.tools.Result;

@Service
public class TaskServiceImpl implements TaskService{
	
	@Resource private TaskMapper taskMapper;
	@Resource private CommonMapper commonMapper;
	

	@Override
	public List<Task> queryTaskList(Map<String, Object> parm) {
		return taskMapper.queryTaskList(parm);
	}

	@Override
	public Result insertTask(Task task) {
		Result ret = new Result();
		int i = taskMapper.insertTask(task);
		if(i==0){
			ret.setMsg("操作失败");
		}
		return ret;
	}

	@Override
	public Result deleteTask(Task task) {
		Result ret = new Result();
		int i = taskMapper.deleteTask(task);
		if(i==0){
			ret.setMsg("操作失败");
		}
		return ret;
	}

	@Override
	public Result updateTask(Task task) {
		Result ret = new Result();
		UpdateMap up = new UpdateMap("task");
		up.addField("acceptStatusCode", task.getAcceptStatusCode());
		up.addWhere("id", task.getId());
		int i = commonMapper.update(up);
		if(i==0){
			ret.setMsg("操作失败");
		}else{
			taskMapper.insertTaskDistribute(task);
		}
		return ret;
	}

	@Override
	public List<Map<String, Object>> queryDistributeList(String id) {
		return taskMapper.queryDistributeList(id);
	}

	@Override
	public List<Map<String, Object>> queryTaskDaily(Map<String, Object> parm) {
		return taskMapper.queryTaskDaily(parm);
	}

	@Override
	public Result overTask(Task task) {
		Result ret = new Result();
		int i = taskMapper.overTask(task);
		if(i==0){
			ret.setStatus("0");
			ret.setMsg("操作失败");
		}
		return ret;
	}

}
